home *** CD-ROM | disk | FTP | other *** search
- Path: news.bellglobal.com!news
- From: Mathieu Frenette <midk@interlinx.qc.ca>
- Newsgroups: comp.lang.c++
- Subject: Q: Template functions with constants instead of types????
- Date: Tue, 05 Mar 1996 22:02:51 -0500
- Organization: Antares Productions
- Message-ID: <313D005B.1E1D@interlinx.qc.ca>
- NNTP-Posting-Host: 204.101.120.37
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 2.0GoldB1 (Win95; I)
-
- First, let's make sure I understand what "template" exactly is... I
- know one can define template functions/classes using general types and
- then use these functions/classes while specifying the needed type and
- the compiler generates all the different cases, one function per type
- used in the program.
-
- Ok, now, let's go with the rough stuff! :) What I want is to be able to
- define a function using a DEFINEd constant (let's name it "CONSTANT")
- and then be able to call the function with CONSTANT having arbitrary
- values. For each value of CONSTANT, the compiler would generate a
- different function.
-
- In example, let's suppose we could define something like :
-
- template <constant T> inline void Func( void )
- {
- printf( "%d\n", T );
- }
-
- And then use it like that :
-
- Func<1>();
- Func<2>();
- Func<3>();
-
- The compiler would generate three similar Func functions with T replaced
- by the values 1,2,3.
-
- If you know the syntax for such a template, PLEASE LET ME KNOW!!! :)
-
- If you're wondering why I'm looking for such a complicated thing, here's
- why :
-
- I have a function that uses a DEFINEd constant (which it absolutely
- needs for optimization reasons) and I want to include this function in a
- library for all my demo group other coders to use. The problem is that,
- if the function is used 4 times in the program, it'll be with 4
- different values assigned to the constant...
-
- If you have any idea else than the "hypothetical" template <const T>,
- please let me know...
-
- Thanks in advance...
- --
- Kind Regards,
- Mathieu.
- --------------------------------------------------------
- Mathieu Frenette, aka ]\/[id ]<night
- Antares Prod.
- <midk@interlinx.qc.ca> Don't let the Bit Bug Byte!
- --------------------------------------------------------
-
-
-